import socket
import threading



def recv_msg(udp_socket):
    while True:
        recv_data = udp_socket.recvfrom(1024)
        print(recv_data)

def send_msg(udp_socket,dest_addr):
    while True:
        content = input('请输入聊天内容')
        udp_socket.sendto(content.encode('utf-8'),dest_addr)
 
def main():
    udp_socket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
    udp_socket.bind(('',7788))
    
    dest_ip = input('请输入对方IP：')
    dest_port = int(input('请输入对方port:'))
    dest_addr = (dest_ip,dest_port)
    
    t_recv = threading.Thread(target = recv_msg,args = (udp_socket,))
    t_send = threading.Thread(target = send_msg,args = (udp_socket,dest_addr))

    t_recv.start()
    t_send.start()


if __name__ == '__main__':
    main()
